package susebs.pb.travel_server.utils.DataInit;

import com.fasterxml.jackson.databind.JsonNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import susebs.pb.travel_server.dao.LandmarksDao;
import susebs.pb.travel_server.dao.PicturesDao;
import susebs.pb.travel_server.entity.Landmarks;
import susebs.pb.travel_server.entity.Pictures;

import java.util.Iterator;

/**
 * 图片信息初始化，用于填充图片数据库
 */
@Component
public class PicturesData {

    private static PicturesDao dao;

//    初始化dao
    @Autowired
    public void setDao(PicturesDao dao){
        PicturesData.dao = dao;
    }

    /**
     *
     * @param links 图片链接
     * @param type 图片类型
     */
    public static void PicturesDataInit(String links,Integer type){
        Pictures picture;
        //用于获取同类图片最新数量，用于关联id的默认填充
        Pictures p1 = new Pictures();
        p1.setPicOwnerEntityType(type);
        long count = dao.count(p1);

        String[] strings = links.split("\n");

        for (String str:strings) {
            picture = new Pictures();

            picture.setPicLink(str);
            picture.setPicOwnerEntityType(type);
            picture.setPicOwnerEntityId(++count);

            if(dao != null){
                dao.insert(picture);
            }else{
                System.out.println("dao为空");
            }

        }

    }

}
